package com.eaoa.uc.document.bo;

import java.util.Date;

import com.eaoa.base.EABaseBusinessObject;
import com.eaoa.dao.pub.PubDocumentDAO;
import com.eaoa.vo.pub.PubDocument;

public class PubDocumentModifyBO extends EABaseBusinessObject {

	private Long documentno;
	private PubDocument vo;

	private static PubDocumentDAO documentDAO = new PubDocumentDAO();

	public PubDocumentModifyBO(PubDocument vo) {
		super();
		this.vo = vo;
	}

	protected void performBusinessLogic() {


		if (vo.getDocumentno() == null) {

			vo.setCreatedate(new Date());
			vo.setCreateby(getEmployee().getAccountno());
			vo.setCreatebyname(getEmployee().getName());

			documentno = (Long) documentDAO.save(vo);

		} else {

			documentno = vo.getDocumentno();

			PubDocument po = (PubDocument) documentDAO.loadAndLock(documentno);

			po.setTitle(vo.getTitle());
			po.setContent(vo.getContent());
			po.setDocumenttype(vo.getDocumenttype());
			po.setRemarks(vo.getRemarks());
			po.setModuleno(vo.getModuleno());
//			po.setPubPermission(vo.getPubPermission());

			documentDAO.update(po);

		}
	}

	public Long getDocumentno() {
		return documentno;
	}

}
